package MyApp.View
{
	import custom.pager.Pager;
	
	import flash.events.MouseEvent;
	import flash.utils.getDefinitionByName;
	import flash.utils.getQualifiedClassName;
	
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	public class CommonMediator extends Mediator
	{
		private var klass:Class;
		private var component:Object;
		
		public var currentState:String;
		public function CommonMediator(mediatorName:String=null, viewComponent:Object=null)
		{
			super(mediatorName, viewComponent);
			
		}
		
		public function CommonRegister(child:Object,component:Object):void{
			//trace("begin common register====="+getQualifiedClassName(child));
			this.klass = Class(getDefinitionByName(getQualifiedClassName(child)));
			this.component=component;
			//翻页
			component.lbtnNext.addEventListener(MouseEvent.CLICK,nextPage);
			component.lbtnPrevious.addEventListener(MouseEvent.CLICK,prevPage);
			component.lbtnFirst.addEventListener(MouseEvent.CLICK,firstPage);
			component.lbtnLast.addEventListener(MouseEvent.CLICK,lastPage);
//			component.lbtnJump.addEventListener(MouseEvent.CLICK,jumPage);
			//刷新
			component.refresh_btn.addEventListener(MouseEvent.CLICK,refresh);
		}
		
		public function refresh(e:MouseEvent):void{
			sendNotification(klass.DO_REFRESH,component.mPager);
			
		}
		
		public function nextPage(e:MouseEvent):void{
			var pager:Pager=component.mPager;
			pager.currPN++;
			sendNotification(klass.DO_REFRESH, pager);
		}
		public function prevPage(e:MouseEvent):void{
			var pager:Pager=component.mPager;
			pager.currPN--;
			sendNotification(klass.DO_REFRESH, pager);
		}
		public function firstPage(e:MouseEvent):void{
			var pager:Pager=component.mPager;
			pager.currPN=1;
			sendNotification(klass.DO_REFRESH, pager);
		}
		public function lastPage(e:MouseEvent):void{
			var pager:Pager=component.mPager;
			pager.currPN=pager.totalPN;
			sendNotification(klass.DO_REFRESH, pager);
		}
		public function jumPage(e:MouseEvent):void{
			var pager:Pager=component.mPager;
			pager.currPN=component.nsPageNum.value;
			sendNotification(klass.DO_REFRESH, pager);
		}
	}
}